package com.ztesoft.book.common.utils.query;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.io.Serializable;
import java.util.List;

/**
 * @Description: 分页工具类
 * @Author: YangFan
 * @Date: 2021-03-19 18:11
 */
public class PageBO implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 总记录数
     */
    private Integer totalCount;

    /**
     * 每页记录数
     */
    private Integer pageSize;

    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 当前页数
     */
    private Integer currPage;

    /**
     * 列表数据
     */
    private List<?> list;


    /**
     * 方法功能描述:
     * < 分页 >
     *
     * @param: 【参数1】 list 列表数据
     * @param: 【参数2】 totalCount 总记录数
     * @param: 【参数3】 pageSize 每页记录数
     * @param: 【参数4】 currPage 当前页数
     * @Return: null
     * @Author: YangFan
     * @Date: 2021-03-19 18:12
     */
    public PageBO(List<?> list, int totalCount, int pageSize, int currPage) {
        this.list = list;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.currPage = currPage;
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }


    /**
     * 方法功能描述:
     * < 分页 >
     *
     * @param: 【参数1】 page
     * @Return: null
     * @Author: YangFan
     * @Date: 2021-03-19 18:13
     */
    public PageBO(IPage<?> page) {
        this.list = page.getRecords();
        this.totalCount = (int) page.getTotal();
        this.pageSize = (int) page.getSize();
        this.currPage = (int) page.getCurrent();
        this.totalPage = (int) page.getPages();
    }

    @Override
    public String toString() {
        return "PageBO{" +
                "totalCount=" + totalCount +
                ", pageSize=" + pageSize +
                ", totalPage=" + totalPage +
                ", currPage=" + currPage +
                ", list=" + list +
                '}';
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getCurrPage() {
        return currPage;
    }

    public void setCurrPage(int currPage) {
        this.currPage = currPage;
    }

    public List<?> getList() {
        return list;
    }

    public void setList(List<?> list) {
        this.list = list;
    }

}
